package org.example.algorithm.sort;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

@Getter
@AllArgsConstructor
public enum SortType {

    SELECT("选择排序", 0),
    BUBBLE("冒泡排序", 1);

    private final String name;

    private final Integer code;

    private static final Map<Integer, SortType> map = new HashMap<>();

    public static SortType getTypeByCode(Integer code) {
        if (map.isEmpty()) {
            synchronized (SortType.class) {
                if (map.isEmpty()) {
                    for (SortType sortType : values()) {
                        map.put(sortType.code, sortType);
                    }
                }
            }
        }
        return map.getOrDefault(code, null);
    }


}
